import { Button, Select, Space, Table, Tag } from 'antd';
import type { ColumnsType } from 'antd/es/table';
import { useEffect, useState } from 'react';
import { ssshop } from '../../dom/httpAPI';
import { Form, Input } from 'antd';


export default function Manageone() {
  const [list, setlist] = useState([])
  const getlist = async () => {
    let res = await ssshop({})
    console.log(res.data);
    setlist(res.data)
  }
  useEffect(() => {
    getlist()
  }, [])
  const columns: ColumnsType<any> = [
    {
      title: '序号',
      dataIndex: 'id',
    },
    {
      title: '标题',
      dataIndex: 'title',
    },
    {
      title: '状态',
      dataIndex: 'collect',
      render: ((collect) => {
        return (
          <Tag>{collect ? "正常" : "停用"}</Tag>
        )
      })
    },
    {
      title: '类型',
      dataIndex: 'type',
      render: ((type, record) => {
        return (
          <Tag color={record.type == "公告" ? 'green' : 'yellow'}>{type}</Tag>
        )
      })
    },
    {
      title: '创作者',
      dataIndex: 'people',
    },
    {
      title: '创作时间',
      dataIndex: 'createTime',
    },

    {
      title: 'Action',
      key: 'action',
      render: (_, record) => (
        <Space size="middle">
          <Button key="bianjibtn">编辑</Button>
          <Button key="shanchubtn">删除</Button>
        </Space>
      ),
    },
  ];

  const onFinish = async (values: any) => {
    console.log('Finish:', values);
    let res = await ssshop(values)
    console.log(res.data);
    setlist(res.data)
  };
  return (

    <div>
      <Form name="horizontal_login" layout="inline" onFinish={onFinish}>
        <Form.Item
          name="like_title"
        >
          <Input placeholder="like_title" />
        </Form.Item>
        <Form.Item
          name="like_people"

        >
          <Input
            placeholder="like_people"
          />
        </Form.Item>
        <Form.Item
          name="like_type"
        >
          <Select

            style={{ width: 120 }}
            options={[
              {
                value: '公告',
                label: '公告',
              },
              {
                value: '通知',
                label: '通知',
              },
            ]}
          />



        </Form.Item>
        <Form.Item shouldUpdate>
          {() => (
            <Button
              type="primary"
              htmlType="submit"
            >
              搜索
            </Button>
          )}
        </Form.Item>
      </Form>
      <Table columns={columns} dataSource={list} rowKey="id" />
    </div>
  )
}
